@extends('layouts.admin')

@section('contents')
<!--面包屑导航 开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin/info')}}">首页</a> &raquo; 全部分类
</div>
<!--面包屑导航 结束-->

<!--结果页快捷搜索框 开始-->
<div class="search_wrap">
    <form action="" method="post">
        <table class="search_tab">
            <tr>
                <th width="120">选择分类:</th>
                <td>
                    <select onchange="javascript:location.href=this.value;">
                        <option value="">全部</option>
                        <option value="http://www.baidu.com">百度</option>
                        <option value="http://www.sina.com">新浪</option>
                    </select>
                </td>
                <th width="70">关键字:</th>
                <td><input type="text" name="keywords" placeholder="关键字"></td>
                <td><input type="submit" name="sub" value="查询"></td>
            </tr>
        </table>
    </form>
</div>
<!--结果页快捷搜索框 结束-->

<!--搜索结果页面 列表 开始-->
<form action="#" method="post">
    <div class="result_wrap">
        <div class="result_title">
        <h3>分类管理</h3>
        </div>
        <!--快捷导航 开始-->
        <div class="result_content">
            <div class="short_wrap">
                <a href="{{url('admin/category/create')}}"><i class="fa fa-plus"></i>新增分类</a>
                <a href="{{url('admin/category')}}"><i class="fa fa-recycle"></i>全部分类</a>
            </div>
        </div>
        <!--快捷导航 结束-->
    </div>

    <div class="result_wrap">
        <div class="result_content">
            <table class="list_tab">
                <tr>
                    <th class="tc" width="5%"><input type="checkbox" name=""></th>
                    <th class="tc" width="5%">排序</th>
                    <th class="tc">ID</th>
                    <th>分类名称</th>
                    <th>分类标题</th>
                    <th>操作</th>
                </tr>
                
                @foreach($data as $d)
                <tr>
                    <td class="tc"><input type="checkbox" name="id[]" value="59"></td>
                    <td class="tc"><input type="text" name="order" onchange="changeOrder(this, {{$d->cate_id}})" value="{{$d->cate_order}}" /></td>
                    <td class="tc">{{$d->cate_id}}</td>
                    <td>
                        <a href="#">{{$d->prefix_cate_name}}</a>
                    </td>
                    <td>{{$d->cate_title}}</td>
                    <td>
                        <a href="{{url('admin/category/'.$d->cate_id.'/edit')}}">修改</a>
                        <a href="javascript:;" onclick="delCate({{$d->cate_id}})">删除</a>
                    </td>
                </tr>
                @endforeach
            </table>
        </div>
    </div>
</form>
<!--搜索结果页面 列表 结束-->

<script>
    function changeOrder(obj, cate_id){
        var inOrder = $(obj).val();
        $.post("{{url('admin/cate/changeorder')}}", 
            {'_token': '{{csrf_token()}}', 'cate_id':cate_id, 'cate_order':inOrder}, 
            function(data){
                if(data.status == 0){
                    location.href = location.href; // 刷新当前页面
                    layer.msg(data.msg, { icon:6, time: 10000, //10s后自动关闭
                                          btn: ['好的']});
                }else
                    layer.msg(data.msg, { icon:5, time: 10000, //10s后自动关闭
                                          btn: ['好的']});
        });
    }
    
    function delCate(cate_id){
        layer.confirm('您是否确定删除该个分类吗？', {
                        btn: ['是','否'] //按钮
                        },                 
        function(){
            $.post("{{url('admin/category')}}/" + cate_id, 
            {'_method':'delete', '_token':'{{csrf_token()}}'}, function(data){
                
                if(data.status == 0){
                    //location.href = location.href; // 刷新当前页面
                    layer.msg(data.msg, { icon:6, time: 10000, //10s后自动关闭
                                          btn: ['好的']});
                }else
                    layer.msg(data.msg, { icon:5, time: 10000, //10s后自动关闭
                                          btn: ['好的']});
            });  
        });
   }

</script>
@endsection